
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
vue-i18n-extensions
Advanced tools
Extensions for vue-i18n
This library exports the following extensions:
v-t
custom directive for server-sidev-t
custom directive compiler module for vue-template-compiler
or vue-loader
(compilerModules
option)$ npm i --save-dev vue-i18n-extensions
v-t
custom directive for server-sideThis directive is v-t
custom directive for server-side-rendering. You can specify it as directives
option of createRenderer
function.
The following example:
import Vue from 'vue'
import VueI18n from 'vue-i18n'
import { createRenderer } from 'vue-server-renderer'
import { directive as t } from 'vue-i18n-extensions'
Vue.use(VueI18n)
const i18n = new VueI18n({
locale: 'en',
messages: {
en: {
hello: 'hello'
},
ja: {
hello: 'こんにちは'
}
}
})
const renderer = createRenderer({ directives: { t } })
const app = new Vue({
i18n,
render (h) {
// <p v-t="'hello'"></p>
return h('p', {
directives: [{
name: 't', rawName: 'v-t',
value: ('hello'), expression: "'hello'"
}]
})
}
})
renderer.renderToString(app, (err, html) => {
console.log(html) // output -> '<p data-server-rendered="true">hello</p>'
})
v-t
custom directive compiler moduleThis module is v-t
custom directive module for vue compiler. You can specify it as modules
option of vue-template-compiler
.
:warning: NOTE: This extension is not isomorphic/universal codes. for Node.js environment only.
The following example that use compile
function of vue-template-compiler
:
import Vue from 'vue'
import VueI18n from 'vue-i18n'
import { compile } from 'vue-template-compiler'
import { module } from 'vue-i18n-extensions'
Vue.use(VueI18n)
const i18n = new VueI18n({
locale: 'en',
messages: {
en: {
hello: 'hello'
},
ja: {
hello: 'こんにちは'
}
},
missing: (locale, key) => {
console.log(`translation missing: locale=${locale}, key=${key}`)
}
})
const i18nModule = module(i18n)
const { ast, render } = compile(`<p v-t="'hello'"></p>`, { modules: [i18nModule] })
console.log(ast.i18n) // output -> 'hello'
console.log(render) // output -> `with(this){return _c('p',{domProps:{"textContent":_s("hello")}})}`
The following configration example of vue-loader
:
const Vue = require('vue')
const VueI18n = require('vue-i18n')
const i18nExtensions = require('vue-i18n-extensions')
const messages = require('./locales.json')
Vue.use(VueI18n)
const i18n = new VueI18n({
locale: 'ja',
messages: messages
})
module.exports = {
module: {
rules: [{
test: /\.vue$/,
loader: 'vue',
options: {
compilerModules: [i18nExtensions.module(i18n)],
// other vue-loader options go here
loaders: {}
}
}]
}
}
Details changes for each release are documented in the CHANGELOG.md.
Please make sure to read the Issue Reporting Checklist before opening an issue. Issues not conforming to the guidelines may be closed immediately.
Please make sure to read the Contributing Guide before making a pull request.
FAQs
vue-i18n extensions
The npm package vue-i18n-extensions receives a total of 1,420 weekly downloads. As such, vue-i18n-extensions popularity was classified as popular.
We found that vue-i18n-extensions demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.